package mysql

import (
	"shop-switcher/shoprpc/shoprpc"

	"gorm.io/gorm"
)

type Shop struct {
	gorm.Model
	ShopName  string  `gorm:"type:varchar(100);not null;commit:'商品名称'"`
	ShopPrice float32 `gorm:"type:decimal(10,2);not null;commit:'商品价格'"`
	ShopNum   int64   `gorm:"type:int(11);not null;commit:'商品数量'"`
	Supplier  string  `gorm:"type:varchar(100);not null;commit:'供应商'"`
	UserId    int64   `gorm:"type:int(11);not null;commit:'userid '"`
}

func (s *Shop) AddShop(db *gorm.DB) error {
	return db.Debug().Create(s).Error
}

func ShopList(db *gorm.DB) {
	var list []*shoprpc.ShopList
	db.Debug().Model(&Shop{}).Select("shops.shop_name", "shops.shop_num", "shops.shop_price", "shops.supplier", "shops.user_id", "users.mobile").Joins("LEFT JOIN users ON shops.user_id = users.id").Find(&list)

}
